define(['angular'], function (angular) {

    var CACHE_ENABLE = true;

    var app = angular.module('webapp', ['ui.router','oc.lazyLoad']);

    //
    app.config(['$ocLazyLoadProvider','$stateProvider', '$urlRouterProvider',
        function ($ocLazyLoadProvider,$stateProvider, $urlRouterProvider) {

            $ocLazyLoadProvider.config({
                loadedModules: ['webapp'],
                asyncLoader: require
            });

            // 定义不匹配路由
            $urlRouterProvider.otherwise('/index');

            // 定义匹配路由
            $stateProvider

                .state('index', {
                    url: '/',
                    templateUrl: 'index.html'
                })

                .state('mod', {

					desc:"子视图模版页",//视图描述
					abstract: true,
					templateUrl: "app/modules/base/tpl.html",
                    resolve: {
                        load: function($ocLazyLoad) {

                            return $ocLazyLoad.load ({
                                name: 'mod',
                                files: ['app/modules/base/ctrl.js'],
                                cache: CACHE_ENABLE 
                            });
                        }
                    }
                })

                .state('mod.dashboard', {
                    desc:"控制面板",
                    url: '/mod/dashboard',
                    templateUrl: 'app/modules/dashboard/tpl.html',
                    resolve: {
                        load: function($ocLazyLoad) {

                            return $ocLazyLoad.load ({
                                name: 'mod',
                                files: ['app/modules/dashboard/ctrl.js'],
                                cache: CACHE_ENABLE 
                            });
                        }
                    }
                })

                .state('mod.listing', {
                    desc:"列表",
                    url: '/mod/listing',
                    templateUrl: 'app/modules/list/tpl.html',
                    resolve: {
                        load: function($ocLazyLoad) {

                            return $ocLazyLoad.load ({
                                name: 'mod',
                                files: ['app/modules/list/ctrl.js'],
                                cache: CACHE_ENABLE 
                            });
                        }
                    }
                });

        }]);

    app.bootstrap = function () {
        angular.bootstrap(document, ['webapp']);
    };


    return app;
});